import {
    defineConfig,
    loadEnv,
} from 'vite'
import legacy from '@vitejs/plugin-legacy';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import path,{ dirname } from 'path';
import { fileURLToPath } from 'url'

const __dirname = dirname(fileURLToPath(import.meta.url));
const {
    npm_package_version,
} = loadEnv('', process.cwd(), '')
// console.log("🚀 ~ file: vite.config.ts:10 ~ defineConfig ~ env", env);

export default defineConfig({
    plugins: [
        viteStaticCopy({
            targets: [
                {
                    src: 'src/tipso.css',
                    dest: 'css'
                }
            ]
        }),
        // legacy({
        //     targets: ['chrome < 70'],
        //     renderLegacyChunks: true, 
        //     // additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
        // })
    ],
    // esbuild: {
    //     drop: ["console", "debugger"],
    // },
    build: {
        target: 'es2015',
        minify: "terser",
        rollupOptions: {
            // input: path.resolve(__dirname, "index.html"),
            input: path.resolve(__dirname, "./src/tipso.js"),
            output: {
                entryFileNames: `[name].${npm_package_version}.min.js`,// 打包的文件名
            },
        },
        copy: ['./src/tipso.css'],
        terserOptions: {
            compress: {
                drop_console: true,
                drop_debugger: true,
            },
            keep_classnames: true,
            keep_fnames: true,
        },
    }
})